import {
  Toast
} from "vant";
import cTitle from "components/title";
export default {
  data() {
    return {
      corporate_name: '', //公司名称
      openingBank: '', //开户行
      subBranch: '', //支行
      bankAccountNumber: '', //银行账号
      remittingBank: '', //汇款银行
      RemittanceAccount: '', //汇款账号
      payer: '', //付款人
      PaymentAmount: '', //付款金额
      paymentvoucher: '', //付款凭证
      uploadUrl: "", //上传图片
      isLoadding: false,
    };
  },

  components: {
    cTitle
  },
  activated() {
    this.uploadUrl = this.fun.getRealUrl("upload.uploadPic", {});
    if (!localStorage.getItem("uid")) {
      this.$router.push(this.fun.getUrl("login"));
      return
    }
    this.getConfig();
    this.initData();
  },
  computed: {

  },
  methods: {
    initData(){
      this.remittingBank = ''; //汇款银行
      this.RemittanceAccount = ''; //汇款账号
      this.payer = ''; //付款人
      this.PaymentAmount = ''; //付款金额
      this.paymentvoucher = ''; //付款凭证
      this.isLoadding = false;
    },
    toBack(){
      this.$router.go(-1);
    },
    // 提交汇款
    submit(){
      if(this.remittingBank == ''){
        Toast('请填写转出银行名称')
        return
      }
     
      if(this.RemittanceAccount == ''){
        Toast('请填写转出银行账号')
        return
      }
      if(this.payer == ''){
        Toast('请填付款人姓名')
        return
      }
      if(this.PaymentAmount == ''){
        Toast('请填写付款金额')
        return
      }
      if(this.paymentvoucher == ''){
        Toast('请填写付款凭证')
        return
      }
      if(this.isLoadding){
        Toast('请勿重复点击')
        return
      }
      this.isLoadding = true;
        $http.get("NiuTwo.huikuan", {
            uid: localStorage.getItem("uid"),
            bank: this.remittingBank,
            bank_num: this.RemittanceAccount,
            user: this.payer,
            money: this.PaymentAmount,
            img: this.paymentvoucher
        }, "加载中").then((res) => {
            if (res.result == 1) {
              Toast('汇款成功')
              setTimeout(()=>{
                this.isLoadding = false;
                this.$router.push(this.fun.getUrl("nnTransferList"));
              },1000)
            }else {
              Toast(res.msg)
              this.isLoadding = false;
            }
          }).catch(err => {
            Toast(err)
            this.isLoadding = false;
          });
    },
    onCopy() {
      Toast({
        message: "复制成功",
        duration: 2000
      });
    },
    /*vant图片上传*/
    onRead(e, flag) {
      console.log(flag.name, "e, flag");
      let typeUpload = flag.name; //0 授权信息 1身份证正面 2身份证反面
      Toast.loading({
        message: "上传中",
        forbidClick: true
      });
      this.stopButton = true;
      let fd = new FormData();

      if (flag === true) {
        fd.append("file", e); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      } else {
        fd.append("file", e.file); // 第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      }
      var That = this;
      axios
        .post(this.uploadUrl, fd, {
          headers: {
            "Content-Type": "multipart/form-data"
          }
        })
        .then(response => {
          var responseData = response.data;
          console.log(responseData, "responseData");
          if (responseData.result === 1) {
            Toast.clear();
            That.paymentvoucher = responseData.data.img_url;
          } else {
            Toast(responseData.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getConfig() {
      $http.get("NiuTwo.huikuan_config", {}, "加载中").then((res) => {
        if (res.result == 1) {
          console.log(res, 'shuju_list')
          this.corporate_name = res.data.niuniu_gongsi;
          this.openingBank = res.data.niuniu_kaihu;
          this.subBranch = res.data.niuniu_zhanghao;
          this.bankAccountNumber = res.data.niuniu_zihang;

        }
      });
    },


  }
};